package com.company;

import java.util.*;

public class Task4 {
    public static void main(String[] args) {
        //todo 4. 编写一段程序，统计这段文字
        // "This class offers constant time performance for the basic operations add remove contains and size"
        // 中不重复词语的数量，并按序列打印输出。
        String str = "This class offers constant time performance for the basic operations add remove contains and size";
        String[] strings = str.split(" ");
        System.out.println(Arrays.toString(strings));

        HashSet<String> repeatSet = new HashSet<>();
        HashSet<String> noRepeatSet = new HashSet<>();

        for (String s: strings) {
            if (repeatSet.contains(s)) {
                noRepeatSet.remove(s);
            } else {
                repeatSet.add(s);
                noRepeatSet.add(s);
            }
        }
        System.out.println(repeatSet.toString());
        System.out.println(noRepeatSet.toString());
        System.out.println("不重复词语的数量: " + noRepeatSet.size());
    }
}
